#include <catch2/catch.hpp>

#include "solution.hpp"

using namespace solution_057;

TEST_CASE("057_insert_interval", "[057]") {
    SECTION("example 1") {
        std::vector< std::vector<int> > intervals{{1,3},{6,9}};
        std::vector newInterval{2,5};
        std::vector< std::vector<int> > ans{{1,5},{6,9}};
        CAPTURE(intervals, newInterval);
        CHECK(Solution().insert(intervals, newInterval) == ans);
    }

    SECTION("example 2") {
        std::vector< std::vector<int> > intervals{{1,2},{3,5},{6,7},{8,10},{12,16}};
        std::vector newInterval{4,8};
        std::vector< std::vector<int> > ans{{1,2},{3,10},{12,16}};
        CAPTURE(intervals, newInterval);
        CHECK(Solution().insert(intervals, newInterval) == ans);
    }

    SECTION("example 3") {
        std::vector< std::vector<int> > intervals{};
        std::vector newInterval{5,7};
        std::vector< std::vector<int> > ans{{5,7}};
        CAPTURE(intervals, newInterval);
        CHECK(Solution().insert(intervals, newInterval) == ans);
    }

    SECTION("example 4") {
        std::vector< std::vector<int> > intervals{{1,5}};
        std::vector newInterval{2,3};
        std::vector< std::vector<int> > ans{{1,5}};
        CAPTURE(intervals, newInterval);
        CHECK(Solution().insert(intervals, newInterval) == ans);
    }

    SECTION("example 5") {
        std::vector< std::vector<int> > intervals{{1,5}};
        std::vector newInterval{2,7};
        std::vector< std::vector<int> > ans{{1,7}};
        CAPTURE(intervals, newInterval);
        CHECK(Solution().insert(intervals, newInterval) == ans);
    }

    SECTION("example 6") {
        std::vector< std::vector<int> > intervals;
        for (int i = 1; i <= 19999; ++i)
            intervals.push_back({i, i + 1});
        std::vector newInterval{0,20001};
        std::vector< std::vector<int> > ans{{0,20001}};
        CHECK(Solution().insert(intervals, newInterval) == ans);
    }
}
